cmake_minimum_required( VERSION 2.6 )

if (NOT CMAKE_BUILD_TYPE)
    set ( CMAKE_BUILD_TYPE Release )
endif (NOT CMAKE_BUILD_TYPE)

if (CMAKE_BUILD_TYPE MATCHES [Dd]ebug)
    message(STATUS "Debug build")
    add_definitions(-DDEBUG)
else()
    message(STATUS "non-debug build")
    add_definitions(-DNDEBUG)
    add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()

if (NOT CMAKE_INSTALL_PREFIX)
    message(FATAL_ERROR "CMAKE_INSTALL_PREFIX is not set but it has to be. Something is wrong.")
endif ()

set(MAJOR_VERSION 0)
set(MINOR_VERSION 4)
set(PATCH_VERSION 0)
set(RAZOR_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
add_definitions(-DRAZOR_VERSION=\"${RAZOR_VERSION}\")
message(STATUS "")
message(STATUS "Razor-qt version: ${RAZOR_VERSION}")
message(STATUS "")

# additional cmake files
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(RazorConfigRegister)


add_definitions ( -Wall )
find_package ( Qt4 4.6.0 REQUIRED )
include ( ${QT_USE_FILE} )
include_directories (
	${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
	${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR}
	)

find_package (UDev REQUIRED)


# This allows to install and read the configs from non-standard locations
add_definitions(-DSHARE_DIR=\"${CMAKE_INSTALL_PREFIX}/share/razor/\")
# razor-config "modules"/desktop files directory
set(RAZOR_CONFIG_MODULES_DIR ${CMAKE_INSTALL_PREFIX}/share/razor/razor-config/)
add_definitions(-DRAZOR_CONFIG_MODULES_DIR=\"${RAZOR_CONFIG_MODULES_DIR}\")

# configuration directory
message(STATUS "")
if (RAZOR_CONFIG_DIR)
    add_definitions(-DRAZOR_CONFIG_DIR=\"${RAZOR_CONFIG_DIR}\")
    message(STATUS "Using config directory $HOME/${RAZOR_CONFIG_DIR}/")
else (RAZOR_CONFIG_DIR)
    message(STATUS "Using default config directory \"$HOME/.razor/\" It can be changed with -DRAZOR_CONFIG_DIR=\".config/razor\" for example.")
endif(RAZOR_CONFIG_DIR)
message(STATUS "")

message(STATUS "Developer documentation (doxygen) can be generated by 'make doc'")
message(STATUS "")


# main build subdirs
add_subdirectory( libraries )
add_subdirectory( razorqt-session )
add_subdirectory( razorqt-panel )
add_subdirectory( razorqt-desktop )
add_subdirectory( razorqt-appswitcher )
add_subdirectory( razorqt-resources )
#add_subdirectory( razorqt-su )
#add_subdirectory( razorqt-x11info )
add_subdirectory( razorqt-runner )
add_subdirectory( razorqt-config )


########### Add uninstall target ###############
CONFIGURE_FILE(
    "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
    IMMEDIATE @ONLY)

ADD_CUSTOM_TARGET(uninstall
    "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")



########## Add make dist target ################
SET(CPACK_PACKAGE_VERSION "${RAZOR_VERSION}")
SET(CPACK_SOURCE_GENERATOR "TBZ2")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "razorqt-${CPACK_PACKAGE_VERSION}")
SET(CPACK_IGNORE_FILES "/CVS/;/\\\\.git\;/\\\\.svn/;\\\\.swp$;\\\\.#;/#;\\\\.tar.gz$;/CMakeFiles/;CMakeCache.txt;refresh-copyright-and-license.pl")
SET(CPACK_SOURCE_IGNORE_FILES ${CPACK_IGNORE_FILES})
INCLUDE(CPack)
# simulate autotools' "make dist"
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)

add_subdirectory( doxygen )
